package com.genesis.yunnanji.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.genesis.yunnanji.R;
import com.luck.picture.lib.tools.ScreenUtils;

/**
 * 创建日期：2018/11/14 0014
 * 作者：Kite
 * 描述：
 */
public class TextBottomActionSheet extends Dialog {

    private Window window;
    private TextView txtContent;

    public TextBottomActionSheet(Context context, String title, String content) {
        super(context, R.style.FullScreenDialogStyle);
        window = getWindow();
//        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setBackgroundDrawable(new ColorDrawable(0x55000000));
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = ScreenUtils.getScreenWidth(context);
        layoutParams.height = ScreenUtils.getScreenHeight(context);
        layoutParams.horizontalMargin = 0;
        layoutParams.gravity = Gravity.BOTTOM;
        window.setAttributes(layoutParams);
        View contentView = View.inflate(context, R.layout.action_sheet_text_bottom, null);
        contentView.setMinimumWidth(10000);
        setContentView(contentView);
        TextView txtTitle = findViewById(R.id.txtTitle);
        txtTitle.setText(title);
        txtContent = findViewById(R.id.txtContent);
        if (!TextUtils.isEmpty(content) && content != null && !content.equals(null)) {
            txtContent.setText(Html.fromHtml(content.replaceAll("\\r\\n", "<br>")));
        } else {
            txtContent.setText("暂无资料");
        }
        txtContent.setMovementMethod(ScrollingMovementMethod.getInstance());
        findViewById(R.id.imgClose).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isShowing()) dismiss();
            }
        });
    }

}
